/*
 * FaceCat图形通讯框架
 * 著作权编号:2015SR229355+2020SR0266727
 * 上海卷卷猫信息技术有限公司
 */

using System;
using System.Collections.Generic;

namespace FaceCat {
    /// <summary>
    /// 日期按钮
    /// </summary>
    public class DayButton {
        /// <summary>
        /// 创建日的按钮
        /// </summary>
        /// <param name="calendar">日历视图</param>
        public DayButton(FCCalendar calendar) {
            m_calendar = calendar;
        }

        public FCRect m_bounds;

        /// <summary>
        /// 获取显示区域
        /// </summary>
        public virtual FCRect getBounds()
        {
            return m_bounds;
        }

        /// <summary>
        /// 设置显示区域
        /// </summary>
        public virtual void setBounds(FCRect bounds)
        {
            m_bounds = bounds;
        }

        public FCCalendar m_calendar;

        /// <summary>
        /// 获取日历视图
        /// </summary>
        public virtual FCCalendar getCalendar()
        {
            return m_calendar;
        }

        /// <summary>
        /// 设置日历视图
        /// </summary>
        public virtual void setCalendar(FCCalendar value)
        {
            m_calendar = value;
        }

        public CDay m_day;

        /// <summary>
        /// 获取保存的日期
        /// </summary>
        public virtual CDay getDay()
        {
            return m_day;
        }

        /// <summary>
        /// 设置保存的日期
        /// </summary>
        public virtual void setDay(CDay value)
        {
            m_day = value;
        }

        public bool m_inThisMonth;

        /// <summary>
        /// 获取是否在本月
        /// </summary>
        public virtual bool inThisMonth()
        {
            return m_inThisMonth;
        }

        /// <summary>
        /// 设置是否在本月
        /// </summary>
        public virtual void setInThisMonth(bool value)
        {
            m_inThisMonth = value;
        }

        public bool m_selected;

        /// <summary>
        /// 获取是否被选中
        /// </summary>
        public virtual bool isSelected()
        {
            return m_selected;
        }

        /// <summary>
        /// 设置是否被选中
        /// </summary>
        public virtual void setSelected(bool value)
        {
            m_selected = value;
        }

        public bool m_visible = true;

        /// <summary>
        /// 获取是否可见
        /// </summary>
        public virtual bool isVisible()
        {
            return m_visible;
        }

        /// <summary>
        /// 设置是否可见
        /// </summary>
        public virtual void setVisible(bool value)
        {
            m_visible = value;
        }

        /// <summary>
        /// 获取绘制的背景色
        /// </summary>
        /// <returns>背景色</returns>
        public virtual long getPaintingBackColor() {
            if (m_selected) {
                return FCColor.Pushed;
            }
            else {
                if (m_inThisMonth) {
                    return FCColor.Hovered;
                }
                else {
                    return FCColor.Back;
                }
            }
        }

        /// <summary>
        /// 获取绘制的边线颜色
        /// </summary>
        /// <returns>边线颜色</returns>
        public virtual long getPaintingBorderColor() {
            return FCColor.Border;
        }

        /// <summary>
        /// 获取要绘制的前景色
        /// </summary>
        /// <returns></returns>
        public virtual long getPaintingTextColor() {
            return FCColor.Text;
        }

        /// <summary>
        /// 触摸点击事件
        /// </summary>
        /// <param name="touchInfo">触摸信息</param>
        public virtual void onClick(FCTouchInfo touchInfo) {
            if (m_calendar != null && m_day != null) {
                m_calendar.setSelectedDay(m_day);
            }
        }

        /// <summary>
        /// 重绘背景方法
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="clipRect">裁剪区域</param>
        public virtual void onPaintBackGround(FCPaint paint, FCRect clipRect) {
            long backColor = getPaintingBackColor();
            paint.fillRect(backColor, m_bounds);
        }

        /// <summary>
        /// 重绘边线方法
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="clipRect">裁剪区域</param>
        public virtual void onPaintBorder(FCPaint paint, FCRect clipRect) {
            long borderColor = getPaintingBorderColor();
            paint.drawLine(borderColor, 1, 0, m_bounds.left, m_bounds.bottom - 1, m_bounds.right - 1, m_bounds.bottom - 1);
            paint.drawLine(borderColor, 1, 0, m_bounds.right - 1, m_bounds.top, m_bounds.right - 1, m_bounds.bottom - 1);
        }

        /// <summary>
        /// 重绘前景方法
        /// </summary>
        /// <param name="paint">绘图对象</param>
        /// <param name="clipRect">裁剪区域</param>
        public virtual void onPaintForeground(FCPaint paint, FCRect clipRect) {
            if (m_day != null) {
                int width = m_bounds.right - m_bounds.left;
                if (width > 0)
                {
                    int height = m_bounds.bottom - m_bounds.top;
                    String dayStr = m_day.getDay().ToString();
                    FCFont font = m_calendar.getFont();
                    FCSize textSize = paint.textSize(dayStr, font, -1);
                    FCRect tRect = new FCRect();
                    tRect.left = m_bounds.left + (width - textSize.cx) / 2;
                    tRect.top = m_bounds.top + (height - textSize.cy) / 2;
                    tRect.right = tRect.left + textSize.cx;
                    tRect.bottom = tRect.top + textSize.cy;
                    paint.drawText(dayStr, getPaintingTextColor(), font, tRect, -1);
                }
            }
        }
    }
}
